package com.stormrage.edu.ctrl.index;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.stormrage.edu.serv.Index.IdxGuideServ;
import com.stormrage.edu.serv.student.StuAcctServ;
import com.stormrage.entity.index.IdxGuide;
import com.stormragetech.core.ctrl.BaseCtrl;

/**
 * @Title: IdxGuideCtrl.java
 * @Package com.stormrage.edu.ctrl.index
 * @Description: 用户指南 Controller
 * @author www.stormragetech.com
 * @date 2016年4月16日
 * @version V1.0
 */
@Controller
@RequestMapping("/guide")
public class IdxGuideCtrl extends BaseCtrl {

	private static final Logger logger = LoggerFactory.getLogger(IdxGuideCtrl.class);

	@Autowired
	private IdxGuideServ idxGuideServ;

	@Autowired
	private StuAcctServ stuAcctServ;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String guide(Model model) {

		logger.debug("【 Controller 】-【 IdxGuideCtrl 】-【 Guide 】-【 GET 】-【 STARTED 】");

		try {

			// ------------------ 获取用户信息 ------------------
			Subject currentUser = SecurityUtils.getSubject();
			if (currentUser.getPrincipal() != null)
				model.addAttribute("user", stuAcctServ.queryByAcct(currentUser.getPrincipal().toString()));

			// ------------------ Controller 操作 ------------------
			IdxGuide guide = idxGuideServ.queryGuide();

			// ------------------ Model 赋值 ------------------
			model.addAttribute("data", guide);

		} catch (Exception e) {
			model.addAttribute("err", e.getMessage());
			return "error/500";
		}

		logger.debug("【 Controller 】-【 IndexCtrl 】-【 Guide 】-【 GET 】-【 COMPLETED 】");
		return "index/guide";

	}

}
